ostbuild: Run triggers after constructing build root
authorColin Walters <walters@verbum.org>
Sun, 15 Jan 2012 22:04:55 +0000 (17:04 -0500)
committerColin Walters <walters@verbum.org>
Sun, 15 Jan 2012 22:05:23 +0000 (17:05 -0500)
Makefile-ostbuild.am
src/ostbuild/pyostbuild/buildutil.py
src/ostbuild/pyostbuild/builtin_chroot_compile_one.py
src/ostbuild/pyostbuild/builtin_chroot_run_triggers.py [new file with mode: 0755]
src/ostbuild/pyostbuild/main.py

index 7cc2ac8b8528362fdb52e8567f26ff7ca94c9cde..327d85ba97be7bf97ee448f0092f078ff7594045 100644 (file)
@@ -25,6 +25,7 @@ pyostbuild_PYTHON =                                   \
        src/ostbuild/pyostbuild/builtin_autodiscover_meta.py    \
        src/ostbuild/pyostbuild/builtin_build.py        \
        src/ostbuild/pyostbuild/builtin_chroot_compile_one.py   \
+       src/ostbuild/pyostbuild/builtin_chroot_run_triggers.py  \
        src/ostbuild/pyostbuild/builtin_commit_artifacts.py     \
        src/ostbuild/pyostbuild/builtin_compile_one.py  \
        src/ostbuild/pyostbuild/builtin_resolve.py      \
index b120fd881b4c1e7c7e780049165906895e3bd54e..3a3716b17827e82588e6db9354889d974af7ddb9 100755 (executable)
 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
 
+import os
 import re
 
 from .subprocess_helpers import run_sync_get_output
 
-ARTIFACT_RE = re.compile(r'^artifact-([^,]+),([^,]+),([^,]+),([^,]+),(.+)-((?:runtime)|(?:devel))\.tar$')
+BUILD_ENV = {
+    'HOME' : '/', 
+    'HOSTNAME' : 'ostbuild',
+    'LANG': 'C',
+    'PATH' : '/usr/bin:/bin:/usr/sbin:/sbin',
+    'SHELL' : '/bin/bash',
+    'TERM' : 'vt100',
+    'TMPDIR' : '/tmp',
+    'TZ': 'EST5EDT'
+    }
+
+def find_user_chroot_path():
+    # We need to search PATH here manually so we correctly pick up an
+    # ostree install in e.g. ~/bin even though we're going to set PATH
+    # below for our children inside the chroot.
+    ostbuild_user_chroot_path = None
+    for dirname in os.environ['PATH'].split(':'):
+        path = os.path.join(dirname, 'linux-user-chroot')
+        if os.access(path, os.X_OK):
+            ostbuild_user_chroot_path = path
+            break
+    if ostbuild_user_chroot_path is None:
+        ostbuild_user_chroot_path = 'linux-user-chroot'
+    return ostbuild_user_chroot_path
 
 def branch_name_for_artifact(a):
     return 'artifacts/%s/%s/%s' % (a['buildroot'],
index cdb2e37a2da15cd45c451c690cc90dc7f4eaf3e7..50d2d3334cfc49685aa5c07121c2318f3ecf7821 100755 (executable)
@@ -21,20 +21,10 @@ import argparse
 import json
 
 from . import builtins
+from . import buildutil
 from .ostbuildlog import log, fatal
 from .subprocess_helpers import run_sync
 
-BUILD_ENV = {
-    'HOME' : '/', 
-    'HOSTNAME' : 'ostbuild',
-    'LANG': 'C',
-    'PATH' : '/usr/bin:/bin:/usr/sbin:/sbin',
-    'SHELL' : '/bin/bash',
-    'TERM' : 'vt100',
-    'TMPDIR' : '/tmp',
-    'TZ': 'EST5EDT'
-    }
-
 class OstbuildChrootCompileOne(builtins.Builtin):
     name = "chroot-compile-one"
     short_description = "Build artifacts from the current source directory in a chroot"
@@ -95,6 +85,8 @@ class OstbuildChrootCompileOne(builtins.Builtin):
                 shutil.rmtree(rootdir_tmp)
             child_args = ['ostree', '--repo=' + args.repo, 'checkout', '-U', rev, rootdir_tmp]
             run_sync(child_args)
+            child_args = ['ostbuild', 'chroot-run-triggers', rootdir_tmp]
+            run_sync(child_args)
             builddir_tmp = os.path.join(rootdir_tmp, 'ostbuild')
             os.mkdir(builddir_tmp)
             os.mkdir(os.path.join(builddir_tmp, 'source'))
@@ -113,18 +105,8 @@ class OstbuildChrootCompileOne(builtins.Builtin):
         output_metadata.close()
         
         chroot_sourcedir = os.path.join('/ostbuild', 'source', self.metadata['name'])
-        
-        # We need to search PATH here manually so we correctly pick up an
-        # ostree install in e.g. ~/bin even though we're going to set PATH
-        # below for our children inside the chroot.
-        ostbuild_user_chroot_path = None
-        for dirname in os.environ['PATH'].split(':'):
-            path = os.path.join(dirname, 'linux-user-chroot')
-            if os.access(path, os.X_OK):
-                ostbuild_user_chroot_path = path
-                break
-        if ostbuild_user_chroot_path is None:
-            ostbuild_user_chroot_path = 'linux-user-chroot'
+
+        ostbuild_user_chroot_path = buildutil.find_user_chroot_path()
         
         child_args = [ostbuild_user_chroot_path, '--unshare-pid', '--unshare-net', '--unshare-ipc',
                       '--mount-readonly', '/',
@@ -143,7 +125,7 @@ class OstbuildChrootCompileOne(builtins.Builtin):
                                '--ostbuild-resultdir=/ostbuild/results',
                                '--ostbuild-meta=_ostbuild-meta'])
             child_args.extend(rest_args)
-        env_copy = dict(BUILD_ENV)
+        env_copy = dict(buildutil.BUILD_ENV)
         env_copy['PWD'] = chroot_sourcedir
         run_sync(child_args, env=env_copy, keep_stdin=args.debug_shell)
         
diff --git a/src/ostbuild/pyostbuild/builtin_chroot_run_triggers.py b/src/ostbuild/pyostbuild/builtin_chroot_run_triggers.py
new file mode 100755 (executable)
index 0000000..bdee64c
--- /dev/null
@@ -0,0 +1,51 @@
+# Copyright (C) 2011,2012 Colin Walters <walters@verbum.org>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+import os,sys,re,subprocess,tempfile,shutil
+from StringIO import StringIO
+import argparse
+import json
+
+from . import builtins
+from . import buildutil
+from .ostbuildlog import log, fatal
+from .subprocess_helpers import run_sync
+
+class OstbuildChrootRunTriggers(builtins.Builtin):
+    name = "chroot-run-triggers"
+    short_description = "Run ostree-run-triggers inside a chroot"
+
+    def execute(self, argv):
+        parser = argparse.ArgumentParser(description=self.short_description)
+        parser.add_argument('root')
+        
+        args = parser.parse_args(argv)
+
+        ostbuild_user_chroot_path = buildutil.find_user_chroot_path()
+
+        child_args = [ostbuild_user_chroot_path,
+                      '--unshare-pid', '--unshare-net', '--unshare-ipc',
+                      '--mount-proc', '/proc', 
+                      '--mount-bind', '/dev', '/dev',
+                      args.root,
+                      '/usr/bin/ostree-run-triggers']
+        print "%r" % (child_args,)
+        env_copy = dict(buildutil.BUILD_ENV)
+        env_copy['PWD'] = '/' 
+        run_sync(child_args, env=env_copy)
+                       
+builtins.register(OstbuildChrootRunTriggers)
index 558957e535bd81ba4975979be7aba28cd2ff5f05..4afb4501dee2ab4c6fc99fb074906ec966168bde 100755 (executable)
@@ -25,6 +25,7 @@ from . import builtins
 from . import builtin_autodiscover_meta
 from . import builtin_build
 from . import builtin_chroot_compile_one
+from . import builtin_chroot_run_triggers
 from . import builtin_commit_artifacts
 from . import builtin_compile_one
 from . import builtin_resolve